raar.external
Class RAExternalAgent

java.lang.Object
  extended by vectorimage.VectorObject
      extended by raar.world.RAWorldObject
          extended by raar.world.RAWorldObjectMovable
              extended by raar.agent.RAAgent
                  extended by raar.external.RAExternalAgent
All Implemented Interfaces:
java.io.Serializable, RAExternalAgentProtocol

public class RAExternalAgent
extends RAAgent
implements RAExternalAgentProtocol

This class models all external agent designs. Adds to the normal RAAgent some capacities with which external agents can be controlled. An external agent is an agent that can also be run outside of SB-MASE, for example physical robots or links to other programs. What basically happens is that SB-MASE reads the sensor values indicated by the external sensors, executes the processes o.t. agent normally, then reads and transfers the actor values back to the extern agent. Communication is modelled with a socket, so that agents can be con- trolled both locally and on a remote system. The communication language used is described in the class RAExternalAgentProtocol.
On the server side of the socket the SBMServer accepts the messages sent by the external agent (as long as there is a server running, obviously). This server has been started with a specific robot model (specified by the ExternalAgentInterface) and just reads sensor values from and writes actor values to this model. In the model, all sensors have a unique id, so that we know which sensor in SB-MASE is which sensor here. Read more on writing your robot models elsewhere - it is quite simple.
When writing your own external agent, all you need to adapt here's the sensor configuration. The external agent therefore must be constructed with sensor config specified in an RAExternalSensor array. This sensor config can not be changed afterwards. Make sure that the sensor id's of the RAExternalSensors match those of the robot model you are using on the server, otherwise the communication between the two parts will screw up.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface raar.external.RAExternalAgentProtocol
RAExternalAgentProtocol.ERROR, RAExternalAgentProtocol.PANIC
 
Field Summary
 
Fields inherited from class raar.agent.RAAgent
AGENT_CLASS_NAME, SIZE
 
Fields inherited from class raar.world.RAWorldObject
SOBJ_AGENT, SOBJ_TRACE
 
Fields inherited from class vectorimage.VectorObject
OBJ_ELLIPSE, OBJ_LINE, OBJ_RECTANGLE
 
Fields inherited from interface raar.external.RAExternalAgentProtocol
AGENT_GO, CONNECT_AGENT, DISCONNECT_AGENT, GET_SENSORS, OK, SHUTDOWN_SERVER
 
Constructor Summary
RAExternalAgent(RAExternalSensor[] sensorConfig)
          Construct an agent with the sensors specified.
RAExternalAgent(RAExternalSensor[] sensorConfig, boolean createActors)
          Construct an agent with the sensors specified.
 
Method Summary
 void addProcess(RAProcess p)
          OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED
 boolean canBeExternal()
          Return whether SB-MASE can use this agent as an external one.
 boolean canBeSimulated()
          Return whether SB-MASE can simulate this agent.
 void cancelConnect()
          Cancel connect operation (has no timeout!)
 void connect(java.lang.String hostH, int portP)
          Connect the agent to a server at host and port given.
 void disconnect()
          Disconnect.
 java.lang.String getHost()
          Return host we're connected to.
 int getPort()
          Return port we're connected to.
 RADataType getSensorValue(RAExternalSensor sensor)
          RUNTIME EXTRA STUFF
 boolean isConnected()
          Return whether this agent is externally connected.
 void messageReceived(java.lang.Object msg)
          Receive a message.
 void pauseAgent()
          Pause agent.
 void removeProcess(RAProcess p)
          OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED
 void replaceProcess(RAProcess p, RAProcess newP)
          OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED
 void runAgent()
          RUNNING THE AGENT IS SLIGHTLY DIFFERENT
 void runAgent(boolean simulated)
          RUNNING THE AGENT IS SLIGHTLY DIFFERENT
 void sendMessage(java.lang.String message)
          Send a message to the robotserver.
 void sendObject(java.lang.Object object)
          Send an object to the robotserver.
 void shutdownSuccessful()
          Indicate that shutdown worked.
 void waitForReply()
          Wait for reply.
 
Methods inherited from class raar.agent.RAAgent
canBeEdited, connect, createGVectorObject, disconnect, dump, getActor, getActorNames, getColor, getConnections, getName, getNormalProcesses, getOtherProcesses, getProcess, getProcesses, getWorld, isEditable, notifyAddedToWorld, notifyAddedToWorld, reset, setName, toString
 
Methods inherited from class raar.world.RAWorldObjectMovable
resetPR, setPR
 
Methods inherited from class raar.world.RAWorldObject
emitsLight, getClassName, isFixed, isLight, isMassive, isMovable, isStatic, moveBy
 
Methods inherited from class vectorimage.VectorObject
contains, getBounds, getPosition, getRotation, getType, isFilled, setBounds, setPosition, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RAExternalAgent

public RAExternalAgent(RAExternalSensor[] sensorConfig)
                throws RAException
Construct an agent with the sensors specified. Automatically create actors too.

Throws:
RAException

RAExternalAgent

public RAExternalAgent(RAExternalSensor[] sensorConfig,
                       boolean createActors)
                throws RAException
Construct an agent with the sensors specified. Specify whether to create actors.

Throws:
RAException
Method Detail

addProcess

public void addProcess(RAProcess p)
                throws RAException
OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED

Overrides:
addProcess in class RAAgent
Throws:
RAException

removeProcess

public void removeProcess(RAProcess p)
                   throws RAException
OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED

Overrides:
removeProcess in class RAAgent
Throws:
RAException

replaceProcess

public void replaceProcess(RAProcess p,
                           RAProcess newP)
                    throws RAException
OVERRIDDEN METHOD, SO THAT SENSOR SETUP IS FIXED

Overrides:
replaceProcess in class RAAgent
Throws:
RAException

runAgent

public void runAgent()
              throws RAException
RUNNING THE AGENT IS SLIGHTLY DIFFERENT

Overrides:
runAgent in class RAAgent
Throws:
RAException

runAgent

public void runAgent(boolean simulated)
              throws RAException
RUNNING THE AGENT IS SLIGHTLY DIFFERENT

Throws:
RAException

pauseAgent

public void pauseAgent()
                throws RAException
Pause agent.

Throws:
RAException

connect

public void connect(java.lang.String hostH,
                    int portP)
             throws RAException
Connect the agent to a server at host and port given.

Throws:
RAException

cancelConnect

public void cancelConnect()
Cancel connect operation (has no timeout!)


disconnect

public void disconnect()
                throws RAException
Disconnect.

Throws:
RAException

sendMessage

public void sendMessage(java.lang.String message)
                 throws java.io.IOException
Send a message to the robotserver.

Throws:
java.io.IOException

sendObject

public void sendObject(java.lang.Object object)
                throws java.io.IOException
Send an object to the robotserver.

Throws:
java.io.IOException

waitForReply

public void waitForReply()
                  throws java.io.IOException
Wait for reply.

Throws:
java.io.IOException

messageReceived

public void messageReceived(java.lang.Object msg)
Receive a message.


shutdownSuccessful

public void shutdownSuccessful()
Indicate that shutdown worked.


canBeSimulated

public boolean canBeSimulated()
Return whether SB-MASE can simulate this agent.

Overrides:
canBeSimulated in class RAAgent

canBeExternal

public boolean canBeExternal()
Return whether SB-MASE can use this agent as an external one.

Overrides:
canBeExternal in class RAAgent

isConnected

public boolean isConnected()
Return whether this agent is externally connected.

Overrides:
isConnected in class RAAgent

getHost

public java.lang.String getHost()
Return host we're connected to.


getPort

public int getPort()
Return port we're connected to.


getSensorValue

public RADataType getSensorValue(RAExternalSensor sensor)
                          throws RAException
RUNTIME EXTRA STUFF

Throws:
RAException